<template>
  <div class="hospital">
    <div class="left">
      <div class="top">
        <el-icon>
          <HomeFilled />
        </el-icon>
        <span> / 医院信息</span>
      </div>
      <!-- 默认激活的选项根据路由参数所决定 -->
      <el-menu class="el-menu-vertical-demo" :default-active="$route.path">
        <el-menu-item index="/hospital/register" @click="changeActive('/hospital/register')"> <el-icon>
            <IconMenu></IconMenu>
          </el-icon>
          <span>预约挂号</span>
        </el-menu-item>
        <el-menu-item index="/hospital/detail" @click="changeActive('/hospital/detail')">
          <el-icon>
            <Document></Document>
          </el-icon>
          <span>医院详情</span></el-menu-item>
        <el-menu-item index="/hospital/notice" @click="changeActive('/hospital/notice')">
          <el-icon>
            <Notification></Notification>
          </el-icon>
          <span>预约通知</span>
        </el-menu-item>
        <el-menu-item index="/hospital/close" @click="changeActive('/hospital/close')">
          <el-icon>
            <InfoFilled></InfoFilled>
          </el-icon>
          <span>停诊信息</span></el-menu-item>
        <el-menu-item index="/hospital/search" @click="changeActive('/hospital/search')">
          <el-icon>
            <Search></Search>
          </el-icon>
          <span>查询/取消</span></el-menu-item> 
      </el-menu>
    </div>
    <div class="right">
      <router-view></router-view>
    </div>
  </div>
</template> 
<script setup lang="ts">
import { HomeFilled, Menu as IconMenu, Document, Notification, InfoFilled, Search } from '@element-plus/icons-vue'
import { onMounted } from "vue";
import { useRouter, useRoute } from 'vue-router';
import useHospitalDetailStore from '@/store/modules/hospitaldetail'
import UserLogin from '@/pages/user/index.vue'

let useDetailStore = useHospitalDetailStore()
let $router = useRouter()
let $route = useRoute()
// 组件挂载时，根据传入的hoscode向服务器请求医院信息
onMounted(() => {
  // 控制台打印，可以看到本身就是字符串，所以直接转换/断言
  useDetailStore.getHospitalDetail($route.query.hoscode as string)
  useDetailStore.getDepartmentInfo($route.query.hoscode as string)
})
const changeActive = (path: string) => {
  $router.push({ path, query: { hoscode: $route.query.hoscode } })
}
</script>

<style scoped lang="scss">
.hospital {
  display: flex;

  .top {
    margin-left: 20px;
    margin-bottom: 10px;
    color: #7f7f7f;
  }

  .left {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .right {
    flex: 8;
  }
}
</style>